<?php

  $per_page = 3;
   
   
 
  //获取地址栏显示的页数
  $cur_page = empty($_GET['p'])?1:$_GET['p'];

  $offset=($cur_page-1)*$per_page;
  
// 调用函数
  $pages = getpages($link,'news',$cur_page);


// $data=getSelect('news',1,'id desc',"$offset,$per_page");
 $sql = "SELECT `news`.*,`cate`.`name`,`admin`.`username` FROM `news`,`cate`,`admin` WHERE news.cate_id=cate.id and news.send_user = admin.id";

// echo $sql;die;
 // $sql = "select `news`.*, `cate`.name from `news`,`cate` where `news`.type=`cate`.id order by `news` .`id` desc limit $offset,$per_page";

// // 执行语句
$result = mysqli_query($link,$sql);


// 因为mysqli_fetch_assoc只查询一次，但数据是多条的，因此可以用while循环实现
 while($arr = mysqli_fetch_assoc($result)){
  //[]代表多维数组
     $data[]=$arr;
}


if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
	$json['data']=$data;
	$json['pages']=$pages;

echo json_encode($json);die;

}

 

//链接news-list.html页面实现视图分离
include (VIEW_PATH.$admin.'layout.html');
 ?>